package com.ch.home.service.serviceImpl.restDishServiceImpl;

import com.ch.home.bean.DishLiterary;
import com.ch.home.mapper.restDishMapper.DishLiteraryMapper;
import com.ch.home.service.serviceInterface.restDishService.DishLiteraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedList;

/**
 * Created by CHEN on 2019/8/28.
 */

@Service
public class DishLiteraryServiceImpl implements DishLiteraryService {

    @Autowired
    DishLiteraryMapper dishLiteraryMapper;

    @Override
    public HashMap getPreview(DishLiterary dishLiterary) {
        return null;
    }

    @Override
    public HashMap getAll(DishLiterary dishLiterary) {
        HashMap<Object, Object> result = new HashMap<>( );
        LinkedList<DishLiterary> dishLiteraryAndSource = dishLiteraryMapper.getDishLiteraryAndSource(dishLiterary);

        if (dishLiteraryAndSource.size( ) > 0) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }

        result.put("value", dishLiteraryAndSource);
        return result;
    }

    @Override
    public HashMap add(DishLiterary dishLiterary) {
        HashMap<Object, Object> result = new HashMap<>( );

        int re = dishLiteraryMapper.addDishLiterary(dishLiterary);
        if (re == 1) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }
        return result;
    }

    @Override
    public HashMap update(DishLiterary dishLiterary) {
        HashMap<Object, Object> result = new HashMap<>( );

        int re = dishLiteraryMapper.updateDishLiterary( dishLiterary);
        if (re == 1) {
            result.put("message", "success");
        } else {
            result.put("message", "fail");
        }
        return result;
    }
}
